<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>基本信息</title>
		<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="black" name="apple-mobile-web-app-status-bar-style" />
		<meta content="telephone=no" name="format-detection" />
		<!-- 引入YDUI样式 -->
		<link rel="stylesheet" href="../build/css/ydui.css" />
		<link rel="stylesheet" href="../css/common.css" />
		<link rel="stylesheet" href="../css/fontcss/css/font-awesome.min.css" />
		
		<style>
			label{
				display: inline-block;
				min-width: 1.2rem;
				text-align: right;
				color:#666666;
			}
			input{
				font-family: sans-serif;
				border:1px solid #eee;
				padding: .1rem .3rem;
				color:#666666;
				}
			.basicinfo{padding: .2rem;}
			.basicinfo div{
				padding: .35rem .2rem;
				position: relative;
			}
			.modifywd{
				margin-left: .1rem;
				padding: .1rem .2rem;
				/* border: 1px solid #eee; */
				border-radius: .1rem;
				color: #ffffff;
				background: #C1060F;
			}
			.modifyinfo{
				color:#cecece;
				padding-left:.2rem ;
			}
			
			#userlogo{
				border-radius: 50%;
				height: 100%;
				width: 100%;
			}
			.logo-wrapper{
				padding: 0 !important;
				position: absolute !important;
				width: .8rem !important;
				height: .8rem !important;
				right: 1rem !important;
				top: 0 !important;
			}			
		</style>
	</head>
	<body>
		<div class="logincantion">
			<header class="m-navbar">
				<a href="#" onClick="javascript :window.history.back(); return false;" class="navbar-item">
					<i class="back-ico"></i>
				</a>
				<div class="navbar-center">
					<span class="navbar-title">基本信息</span>
				</div>
			</header>
			<div class="basicinfo">
				<div style="position: relative;">
					<label>头像：</label>
					<div class="logo-wrapper">
						<img id="userlogo" style="width:100%" onclick="$('#sfz_1').click()"  />
						<input type="file" class="ajax-upload" accept="image/gif,image/jpeg,image/x-png"   id="sfz_1"  style="display:none">
					</div>
				</div>
				<div>
					<label>密码：</label>
					<input type="password" readonly="readonly" value="000" name="password" />
					<a href="#"  class="modifywd">修改</a>
				</div>
				<div>
					<label>昵称：</label>
					<input type="text"   value="" name="name"/>
				</div>
				<div>
					<label>主营地区：</label>
					<input type="text"    value="" name="area"/>
				</div>
				<div>
					<label>用户身份：</label>
					<input type="text" readonly="readonly"    value="" name="usertype"/>
				</div>
				<div>
					<label>所属门店：</label>
					<input type="text" readonly="readonly"    value="" name="belong"/>					
				</div>				
			</div>
			<p class="modifyinfo">&nbsp;*&nbsp;基本信息编辑即可修改！</p>
		</div>
		<!-- 报备客户按钮 -->
		<a href="./reportecustomers/homebaobei.html">
			<div id="preparation">报备</div>
		</a>
	</body>
	<!-- 引入YDUI自适应解决方案类库 -->
	<script src="../build/js/ydui.flexible.js"></script>
	<script src="../js/jq331.min.js"></script>
	<script src="../js/exif.js"></script>
	<!-- 引入YDUI脚本 -->
	<script src="../build/js/ydui.js"></script>
	<script src="../js/common.js"></script>
	<script>
		$(document).ready(function(){
			var tel;
			//获取用户基本信息
			var getuserinfoApi = commapi + "user/info";//获取信息
			var modifyinfoApi = commapi + 'user/update';//修改信息
			var modifylogoApi = commapi + 'user/head_img'; //修改头像			
			$.ajax({
				url: getuserinfoApi,
				type: 'GET',									
				data: {},
				beforeSend: function(request) {
						request.setRequestHeader("token", dataToken);
						},
				success: function (ret) {	
					$('#userlogo').attr('src',ret.head_img);
					$("input[name='name']").val(ret.nickname);
					$("input[name='area']").val(ret.area);
					$("input[name='belong']").val(ret.store_id);
					$("input[name='usertype']").val(ret.level);
					tel = ret.phone
				}
			});
			//修改密码
			$('.modifywd').click(function(){
				location.href="./modifywd.html?tel="+ tel;
			})
			//修改基本信息
			$(".basicinfo div input").blur(function(){
				var currentVal = $.trim($(this).val());				
				if(currentVal !=''){
					if($(this).attr('name')=='name'){
						var data={
							'nickname': currentVal
						}
					}else if($(this).attr('name')=='area'){
						var data={
							'area': currentVal
						}
					}else{
						var data={
							'store_name': currentVal
						}
					}
					$.ajax({
						url: modifyinfoApi,
						type: 'POST',									
						data: data,
						beforeSend: function(request) {
								request.setRequestHeader("token", dataToken);
								},
						success: function (ret) {	
							YDUI.dialog.toast('信息更新成功', 'none', 1500);
							
						},
						error:function(msg){
							var json=JSON.parse(msg.responseText);
							YDUI.dialog.toast(json.msg, 'none', 2000); // 失败返回
						}
					});						
				}else{
					YDUI.dialog.toast('修改内容不能为空！', 'none', 1500);
				}
			});	
						
			//换头像			
			$('.ajax-upload').on('change',function(){//当 input file 已经选中时触发js							
			var formData = new FormData();//先实例化formdata
			var  file = this.files[0];//获取文件名
			var id   = this.id;//本input的id		
				
			formData.append("head_img", file);//append方法用于向formdata中注入内容
			
			$.ajax({
				type: "post",
				url: modifylogoApi,
				//async:false,
				contentType: false,
				processData: false,
				data: formData,//传过来
				dataType: 'json',
				cache: false,
				contentType: false,
				processData: false,
				beforeSend: function(request) {
						request.setRequestHeader("token", dataToken);
						},
				success: function (data) {
					console.log(data)
					window.location.reload();
		　　　　　　　//$('#userlogo').attr('src',data.url);//改变当前的显示图片										
					
				},
				error: function(err){
					console.log(err)
					window.location.reload();
				}
			});
		});										
	});
	</script>
</html>
